package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 练习创建表:student1
 * 字段：
 * id int
 * name varchar
 * age int
 * class_id int
 *
 */
public class Test {
    public static void main(String[] args) throws ClassNotFoundException {
        Class.forName("com.mysql.cj.jdbc.Driver");//mysql固定就是这个
        //URL格式-> jdbc:不同数据库有自己格式的部分/数据库名?参数
        try(
                Connection connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root");
        ) {
            Statement state = connection.createStatement();
            String sql = "CREATE TABLE student1(" +
                    "       id INT AUTO_INCREMENT PRIMARY KEY," +
                    "       name VARCHAR(30)," +
                    "       age INT(3)," +
                    "       class_id INT" +
                    ")";
            state.execute(sql);
            System.out.println("执行完毕");
        }catch(SQLException e){
            e.printStackTrace();
        }

    }
}
